home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 2002 November / SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso / dist / insight_base.idb / usr / sbin / insightAdmin.z / insightAdmin
Text File  |  2002-10-15  |  19KB  |  773 lines

  1. #!/usr/bin/perl
  2. #
  3. # Copyright 2002, Silicon Graphics, Inc.
  4. # All Rights Reserved.
  5. #
  6. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  7. # the contents of this file may not be disclosed to third parties, copied or
  8. # duplicated in any form, in whole or in part, without the prior written
  9. # permission of Silicon Graphics, Inc.
  10. #
  11. # RESTRICTED RIGHTS LEGEND:
  12. # Use, duplication or disclosure by the Government is subject to restrictions
  13. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  14. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  15. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  16. # rights reserved under the Copyright Laws of the United States.
  17. #
  18. # ----------------------
  19. # insightAdmin (Insight)
  20. # ----------------------
  21. # syntax:
  22. #
  23. #    insightAdmin [-c] [-d] [-v] [-h] [ <bookshelf> ]
  24. #    ex: insightAdmin /usr/share/Insight/library/SGI_bookshelves/SGI_EndUser
  25. #
  26.  
  27. $| = 1;
  28.  
  29. my($_VRS)     = 'v5.1';
  30. my(@_bkshlfs) = ();
  31. my($_lpth)    = '/usr/share/Insight/library/SGI_bookshelves';
  32. my($_url)     = 'http://techpubs.sgi.com/bkdl.cgi';
  33. my($_lang)    = 'C';
  34. my($_ebt2html)= '/usr/share/Insight/bin/ebt2html';
  35.  
  36. my($_verbose, $_correct, $_dl) = 0;
  37.  
  38. my(%_strs)    = (
  39.  
  40.   # shelf titles, etc
  41.  
  42.     'SGI_EndUser'   => 'End-User',
  43.     'SGI_Admin'     => 'Administrative',
  44.     'SGI_Developer' => 'Developer',
  45.     'SGI_Service'   => 'Service',
  46.     'Help'          => 'Application Help',
  47.     'ISV_Help'      => '3rd Party Application Help',
  48.  
  49.   # html 
  50.  
  51.     'html_ftr'      => "</p>\n</body></html>\n",
  52.  
  53.   # error/misc strings
  54.  
  55.     'err_inv_s'     => 'invalid bookshelf',
  56.     'err_inv_s_c'   => 'invalid bookshelf; cannot correct',
  57.     'err_no_s'      => 'no bookshelves found; cannot process default',
  58.     'pr'            => 'processing',
  59.     'add'           => 'adding',
  60.     'warn'          => 'WARNING',
  61.     'err'           => 'ERROR',
  62.     'old_form1'     => "appears to be in old/unreadable format\n\t\t\t  (see -c and -d options)\n",
  63.     'old_form2'     => '(old/unreadable format)',
  64.     'pdf_form'      => "is only available in PDF\n",
  65.     'pdf'           => 'PDF copy',
  66.     'dn'            => 'document number',
  67.     'dl'            => 'downloading',
  68.     'err_dl'        => 'ERROR downloading',
  69.     'cv'            => 'converting',
  70.     'err_cv'        => 'ERROR converting',
  71.     'err_wr'        => 'cannot write to',
  72.     'rt'            => 'return to',
  73.     'list_s'        => 'List of Bookshelves'
  74. );
  75.  
  76.  
  77. #----------------------
  78. # read in cmd-line args
  79. #
  80. while ((@ARGV + 0) > 0) {
  81.  
  82.      if ($ARGV[0] =~ /^\-/) {
  83.  
  84.          if ($ARGV[0] =~ /v/i) {
  85.              $_verbose = 1;       # (v)erbose mode
  86.          } 
  87.          if ($ARGV[0] =~ /h/i) {
  88.              &usage('');          # (h)elp/usage
  89.          }
  90.          if ($ARGV[0] =~ /c/i) {
  91.              $_correct = 1;       # (c)orrect old books
  92.          } 
  93.          if ($ARGV[0] =~ /d/i) {
  94.              $_dl = 1;            # use net to (d)ownload new format bks
  95.          }
  96.          if ($ARGV[0] =~ /n/i) {
  97.              shift(@ARGV);
  98.              $_lang = $ARGV[0];   # lang variable; not public
  99.          }
  100.  
  101.      } else {
  102.  
  103.          if (-d $ARGV[0] && -d "$ARGV[0]/books") {
  104.              push(@_bkshlfs, $ARGV[0]);
  105.          } else {
  106.              &usage("$_strs{'err_inv_s'} ($ARGV[0])");
  107.          }
  108.      }
  109.      shift(@ARGV);
  110. }
  111.  
  112. if ($_dl == 1) {
  113.    my($e_str) = $ENV{TPL_SERVER}; 
  114.    if ($e_str ne '') {
  115.        $_url =~ s/\/\/[^\/]+\//\/\/${e_str}\//;
  116.    }
  117. }
  118.  
  119.  
  120. #---------------------------------------------------------
  121. # set the proper locale for us to work in...
  122. #
  123. # LC_CTYPE   needed for uc{first}, lc{first}
  124. # LC_COLLATE needed for lt, le, cmp, ge, gt, strcoll, sort
  125. #
  126. use locale;
  127. use POSIX qw(locale_h);
  128. use POSIX qw(strcoll);
  129.  
  130. if ($_lang ne '') {
  131.  
  132.     if (!(setlocale(LC_CTYPE, $_lang))) {
  133.  
  134.           # on error, set to 'C'
  135.           #
  136.           $_lang = 'C'; 
  137.           setlocale(LC_CTYPE, $_lang);
  138.     }
  139.     setlocale(LC_COLLATE, $_lang);
  140. }
  141.  
  142.  
  143. #-----------------------------------------------------------
  144. # use a default...all bookshelves under default library path
  145. #
  146. if ((@_bkshlfs+0) == 0) {
  147.  
  148.    opendir(LDIR, "${_lpth}") || &usage("$_strs{'err_no_s'} (${_lpth}");
  149.    foreach (readdir(LDIR)) {
  150.  
  151.          if ($_ !~ /^\./ && -d "${_lpth}/${_}/books") {
  152.              push(@_bkshlfs, "${_lpth}/${_}");
  153.          }
  154.    }
  155.    closedir (LDIR);
  156.  
  157.    if ((@_bkshlfs+0) == 0) {
  158.       &usage("$_strs{'err_no_s'} (${_lpth}");
  159.    }
  160. }
  161.  
  162.  
  163. #-------------------
  164. # open html template
  165. #
  166. $_hdr = '';
  167. while(<DATA>) {
  168.       $_hdr .= $_;
  169. }
  170. close(DATA);
  171.  
  172.  
  173. #------------------------
  174. # process the bookshelves
  175. #
  176. foreach (@_bkshlfs) {
  177.  
  178.     if ($_verbose) {
  179.         print "\ninsightAdmin ($_VRS): $_strs{'pr'} ${_}\n\n";
  180.     }
  181.  
  182.     if ($_correct == 1) {
  183.         &correct_bookshelf($_);
  184.     }
  185.  
  186.     &update_bookshelf($_);
  187. }
  188.  
  189.  
  190. #------------------------------------
  191. # add a library-level index.html file
  192. #
  193. &add_lib_html($_bkshlfs[0]);
  194.  
  195.  
  196. exit(0);
  197.  
  198.  
  199.  
  200. #------------------------------------------------------------
  201. # update_bookshelf(string bkshlf)
  202. #
  203. #  create/write to booklist.txt and top-level index.html file
  204. #
  205. sub update_bookshelf {
  206.  
  207.    my($bkshlf) = @_;
  208.    if ($bkshlf eq '' || !(-d "$bkshlf")) {
  209.        &usage("$_strs{'err_inv_s'} (${bkshlf})");
  210.    }
  211.  
  212.    my($shlf_name) = ($bkshlf =~ m#/([^/]+)$#s);
  213.  
  214.    #-----------------------------------------------------
  215.    # prepare list of books to process/add to booklist.txt
  216.    #
  217.    my($s, $pth, $tmp, $bk, $dn, $btype, $ttl, $html, $pdf) = '';
  218.    my(%books) = ();
  219.  
  220.    opendir(BKDIR, "${bkshlf}/books") || 
  221.                                   &usage("$_strs{'err_inv_s'} (${bkshlf})");
  222.    foreach $s (readdir(BKDIR)) {
  223.  
  224.       if ($s =~ /^\./) {
  225.           next;
  226.       }
  227.  
  228.       $bk = $s;
  229.       ($dn, $ttl, $btype) = '';
  230.  
  231.       if ($_verbose) {
  232.           print "          $_strs{'add'} $bk...\n";
  233.       }
  234.  
  235.       #-----------------------------
  236.       # use existing booklist.txt...
  237.       #
  238.       if (-r "${bkshlf}/books/${s}/booklist.txt") {
  239.  
  240.           open(BKL, "${bkshlf}/books/${s}/booklist.txt");
  241.           $tmp = join('', <BKL>);
  242.           close(BKL);
  243.  
  244.           $tmp =~ s/<COLLECTION>\n//i;
  245.           $tmp =~ s/<\/COLLECTION>\n//i;
  246.           if( $tmp !~ /<\/BOOK>\n$/i ) {
  247.               $tmp .= "</BOOK>\n";
  248.           }
  249.           if( $tmp =~ /.*(\d\d\d-\d\d\d\d-\d\d\d[a-zA-Z]*).*/ ) {
  250.               $dn = $1;
  251.           }
  252.           if( $tmp =~ /ALIAS[\ \=]+\"([^\"]+)\"/i ) {
  253.               $ttl = $1;
  254.           }
  255.           if( $tmp =~ /GROUP[\ \=]+\"([^\"]+)\"/i ) {
  256.               $btype = $1;
  257.           }
  258.  
  259.       #-----------------
  260.       # ...or create one
  261.       #
  262.       } else {
  263.  
  264.           $dn = '';
  265.           if (-l "${bkshlf}/books/$s") {
  266.               $tmp = `ls -l ${bkshlf}/books/${s}`;
  267.               if ($tmp =~ /.*(\d\d\d-\d\d\d\d-\d\d\d[a-zA-Z]*).*/) {
  268.                   $dn = $1;
  269.               }
  270.           }
  271.           $ttl = $s;
  272.           $tmp = "<BOOK NAME=\"" . $s . "\" ALIAS=\"" . $s . "\"" .
  273.                  ($dn ne '' ? " SGIVERSION=\"${dn}\"" : '') .
  274.                  ">\n</BOOK>\n";
  275.       }
  276.  
  277.       if ($_verbose) {
  278.           if ($btype !~ /html/i &&  &check_book($bkshlf, $bk) == 0) {
  279.               print "                 ", $_strs{'warn'}, ": $bk ",
  280.                     (&check_pdf($bkshlf, $bk) == 1 ? 
  281.                                   $_strs{'pdf_form'} : $_strs{'old_form1'});
  282.           }
  283.       }
  284.  
  285.       ($pth, $pdf) = '';
  286.       if (-e "${bkshlf}/books/${bk}/sgi_html/index.html") {
  287.           $pth = "<a href=\"books/${bk}/sgi_html/index.html\">";
  288.       } elsif(-e "${bkshlf}/books/${bk}/index.html") {
  289.           $pth = "<a href=\"books/${bk}/index.html\">";
  290.       } elsif(-d "${bkshlf}/books/${bk}/sgi_html") {
  291.           $pth = "<a href=\"books/${bk}/sgi_html/\">";
  292.       } 
  293.       if (-e "${bkshlf}/books/${bk}/pdf/${bk}.pdf") {
  294.           $pdf = "<a href=\"books/${bk}/pdf/${bk}.pdf\">";
  295.       } elsif(-e "${bkshlf}/books/${bk}/${bk}.pdf") {
  296.           $pdf = "<a href=\"books/${bk}/${bk}.pdf\">";
  297.       }
  298.  
  299.       $html = "<li>${pth}<b>" . ($ttl ne '' ? "$ttl" : "$s") . "</b>";
  300.       if ($pth ne '') {
  301.           $html .= "</a>";
  302.       } elsif ($pdf eq '') {
  303.           $html .= "  <i>$_strs{'old_form2'}</i>";
  304.       }
  305.       if ($pdf ne '') {
  306.           $html .= "  ${pdf}$_strs{'pdf'}</a>";
  307.       }
  308.       $html .= ($dn ne '' ? "<br><i>($_strs{'dn'}: ${dn})</i>" : '') . 
  309.                "</li>\n";
  310.  
  311.  
  312.       $books{$s} = { 'title'    => $ttl,
  313.                      'booklist' => $tmp,
  314.              'html'     => $html
  315.                    };
  316.  
  317.       #------------------------
  318.       # clean-up 0-length files
  319.       #
  320.       &clean_bookdir("${bkshlf}/books/${bk}", "${bk}");
  321.    }
  322.  
  323.    closedir(BKDIR);
  324.  
  325.    #---------------------------------------------------------------
  326.    # sort the books by title and create booklist.txt and index.html
  327.    #
  328.    open(FP_BKLIST, "> ${bkshlf}/booklist.txt") || do {
  329.      &usage("$_strs{'err_wr'} ${bkshlf}/booklist.txt");
  330.    };
  331.    open(FP_BKHTML, "> ${bkshlf}/index.html") || do {
  332.      &usage("$_strs{'err_wr'} ${bkshlf}/index.html");
  333.    };
  334.  
  335.    print FP_BKLIST "<COLLECTION>\n";
  336.    print FP_BKHTML &do_html(($_strs{$shlf_name} ne '' ? 
  337.                              $_strs{$shlf_name} : ${shlf_name})),
  338.                    "<p>($_strs{'rt'} <a href=\"../index.html\">", 
  339.                    lc($_strs{'list_s'}), "</a>)</p>\n<p><ul>\n";
  340.  
  341.    foreach $book 
  342.      (sort { lc($books{$a}->{'title'}) cmp lc($books{$b}->{'title'}) } 
  343.                                                             (keys(%books))) {
  344.       print FP_BKLIST $books{$book}->{'booklist'};
  345.       print FP_BKHTML $books{$book}->{'html'};
  346.    }
  347.  
  348.    print FP_BKLIST "</COLLECTION>\n";
  349.    print FP_BKHTML "</ul>", $_strs{'html_ftr'};
  350.    close(FP_BKLIST);
  351.    close(FP_BKHTML);
  352.  
  353.  
  354.  
  355. #---------------------------------------------------
  356. # correct_bookshelf(string bkshlf)
  357. #
  358. #  check for old books, update to new format w/tools
  359. #
  360. sub correct_bookshelf {
  361.  
  362.    my($bkshlf) = @_;
  363.    if ($bkshlf eq '' || !(-d "$bkshlf")) {
  364.        &usage("$_strs{'err_inv_s_c'} (${bkshlf})");
  365.    }
  366.  
  367.    my($shlf_name) = ($bkshlf =~ m#/([^/]+)$#s);
  368.  
  369.    #------------
  370.    # check books
  371.    #
  372.    my($s, $tmp, $bk, $dn, $btype) = '';
  373.    my($ok) = 0;
  374.  
  375.    opendir(BKDIR, "${bkshlf}/books") || 
  376.                                    &usage("$_strs{'err_inv_s'} (${bkshlf})");
  377.    foreach $s (readdir(BKDIR)) {
  378.  
  379.       if ($s =~ /^\./) {
  380.           next;
  381.       }
  382.  
  383.       #--------------
  384.       # in new format
  385.       #
  386.       if (&check_book($bkshlf, $s) == 1) {
  387.           next;
  388.       }
  389.  
  390.       ($dn, $btype, $pth) = '';
  391.  
  392.       #-----------------------------------
  393.       # query booklist.txt for part number
  394.       #
  395.       if (-r "${bkshlf}/books/${s}/booklist.txt") {
  396.  
  397.           open(BKL, "${bkshlf}/books/${s}/booklist.txt");
  398.           $tmp = join('', <BKL>);
  399.           close(BKL);
  400.  
  401.           if ($tmp =~ /.*(\d\d\d-\d\d\d\d-\d\d\d[a-zA-Z]*).*/) {
  402.               $dn = $1;
  403.           }
  404.           if( $tmp =~ /GROUP[\ \=]+\"([^\"]+)\"/i ) {
  405.               $btype = $1;
  406.           }
  407.       }
  408.  
  409.       if ($btype =~ /html/i) {
  410.           next;  # ignore (old) HTML books
  411.       }
  412.  
  413.       if ($dn eq '') {
  414.           $dn = "${shlf_name}/${s}";
  415.       }
  416.  
  417.       #-------------------------------
  418.       # perform conversion or download
  419.       #
  420.       $ok = 0;
  421.       if ($_dl == 1) {
  422.  
  423.           if ($_verbose) {
  424.              print "          ",
  425.                    "$_strs{'dl'} ${shlf_name}/books/${s}...\n";
  426.           }
  427.           if (($ok = &download_book($bkshlf, $s, $dn)) == -1) {
  428.              print "            ",
  429.                    "$_strs{'err_dl'} ${shlf_name}/books/${s}\n";
  430.           }
  431.       }
  432.       
  433.       if ($ok <= 0) {
  434.  
  435.           #----------------------
  436.           # use filter conversion
  437.           #
  438.           if ($_verbose) {
  439.              print "          $_strs{'cv'} ${shlf_name}/books/${s}...\n";
  440.           }
  441.           if (($ok = &convert_book($bkshlf, $s)) == -1) {
  442.              print "          $_strs{'err_cv'} ${shlf_name}/books/${s}\n";
  443.           }
  444.       }
  445.    }
  446.  
  447.    closedir(BKDIR);
  448. }
  449.  
  450.  
  451.  
  452. #--------------------------------------------------------
  453. # download_book (string bkshlf, string bk, string docnum)
  454. #
  455. #  fetch a book from techpubs.sgi.com 
  456. #
  457. sub download_book {
  458.  
  459.    my($bkshlf, $bk, $dn) = @_;
  460.  
  461.    #---------------------------------------------
  462.    # geturl does a fetch, returns a temp filename
  463.    #
  464.    my($tmp) = `geturl '${_url}/${dn}'`;
  465.    if ($? || !(-r "${tmp}")) {
  466.        return -1;
  467.    }
  468.  
  469.    if (int((-s "${tmp}")) < 500) {
  470.        system("rm -f ${tmp}");
  471.        return -1;
  472.    }
  473.  
  474.    if (!(-d "${bkshlf}/books/.sgitmp")) {
  475.        if (!(mkdir("${bkshlf}/books/.sgitmp", 0755))) {
  476.            return -1;
  477.        }
  478.    } else {
  479.        system("rm -rf ${bkshlf}/books/.sgitmp/*");
  480.        if ($?) {
  481.            return -1;
  482.        }
  483.    }
  484.  
  485.    my($cmd) = "(mv -f ${tmp} ${tmp}.gz; ".
  486.               " gunzip -f -q ${tmp}.gz; " .
  487.               " cd ${bkshlf}/books/.sgitmp; " .
  488.               " tar -xf ${tmp}; " .
  489.               " rm -f ${tmp})";
  490.    system("$cmd");
  491.    if ($?) {
  492.        system("rm -rf ${bkshlf}/books/.sgitmp");
  493.        return -1;
  494.    }
  495.  
  496.    $tmp = `ls -1 ${bkshlf}/books/.sgitmp`;
  497.    $tmp =~ s/\n$//g;
  498.  
  499.    if (-d "${bkshlf}/books/.sgitmp/${tmp}") {
  500.  
  501.        $cmd = "(mv -f ${bkshlf}/books/${bk} ${bkshlf}/books/${bk}.O; " .
  502.               " mv -f ${bkshlf}/books/.sgitmp/${tmp} ${bkshlf}/books/${bk})";
  503.        system("$cmd");
  504.  
  505.        #--------------
  506.        # recovery step
  507.        #
  508.        if ($?) {
  509.  
  510.           if (-d "${bkshlf}/books/${bk}.O") {
  511.               $cmd = "(mv -f ${bkshlf}/books/${bk}.O ${bkshlf}/books/${bk}; " .
  512.                      " rm -rf ${bkshlf}/books/.sgitmp)";
  513.               system("$cmd");
  514.           }
  515.           return -1;
  516.        }
  517.  
  518.        if (-d "${bkshlf}/books/${bk}.O") {
  519.            system("rm -rf ${bkshlf}/books/${bk}.O");
  520.        }
  521.    }
  522.  
  523.    system("rm -rf ${bkshlf}/books/.sgitmp");
  524.    return 1;
  525. }
  526.  
  527.  
  528.  
  529. #---------------------------------------
  530. # convert_book(string bkshlf, string bk)
  531. #
  532. #  filter/convert book to new format
  533. #
  534. sub convert_book {
  535.  
  536.    my($bkshlf, $bk) = @_;
  537.  
  538.    if ($bkshlf eq '' || $bk eq '' || !(-d "${bkshlf}/books/${bk}")) {
  539.        return -1;
  540.    }
  541.  
  542.    my($cmd) = $_ebt2html . ($_verbose ? ' -v' : '') . " $bkshlf $bk";
  543.  
  544.    $result = system($cmd);
  545.  
  546.    return ($result);
  547. }
  548.  
  549.  
  550.  
  551. #--------------------------------------------
  552. # add_lib_html(string bkshlf)
  553. #
  554. #  create top-level (library) index.html file
  555. #
  556. sub add_lib_html {
  557.  
  558.    my($bkshlf) = @_;
  559.  
  560.    my($lib) = $bkshlf;
  561.    $lib =~ s/[^\/]+$//;
  562.    if ($lib eq '' || !(-d "$lib")) {
  563.        return;
  564.    }
  565.  
  566.    opendir(LIBDIR, "${lib}") || return;
  567.  
  568.    open(FLIBHTML, "> ${lib}/index.html") || return;
  569.    print FLIBHTML &do_html($_strs{'list_s'}), "\n<p><ul>\n";
  570.  
  571.    foreach (readdir(LIBDIR)) {
  572.  
  573.       if ($_ =~ /^\./
  574.           || !(-f "${lib}${_}/booklist.txt")
  575.           || !(-f "${lib}${_}/index.html")) {
  576.           next;
  577.       }
  578.       print FLIBHTML "<li><a href=\"${_}/index.html\"><b>",
  579.                      ($_strs{$_} ne '' ? $_strs{$_} : ${_}), "</b></a></li>\n";
  580.    }
  581.  
  582.    closedir(LIBDIR);
  583.  
  584.    print FLIBHTML "</ul>", $_strs{'html_ftr'};
  585.    close(FLIBHTML);
  586. }
  587.  
  588.  
  589.  
  590. #---------------------------------------
  591. # check_book(string bkshlf, string bk)
  592. #
  593. #  check to see if book is in old format
  594. #
  595. sub check_book {
  596.  
  597.    my($bkshlf, $bk) = @_;
  598.  
  599.    if ($bkshlf eq '' || $bk eq '' || !(-d "${bkshlf}/books/${bk}")) {
  600.        return 0;
  601.    }
  602.  
  603.    #--------------
  604.    # in new format
  605.    #
  606.    if (-d "${bkshlf}/books/${bk}/sgi_data"
  607.        &&
  608.        -f "${bkshlf}/books/${bk}/sgi_html/index.html") {
  609.        return 1;
  610.    }
  611.  
  612.    return 0;
  613. }
  614.  
  615.  
  616. #------------------------------------
  617. # check_pdf(string bkshlf, string bk)
  618. #
  619. #  check to see if book is in PDF
  620. #
  621. sub check_pdf {
  622.  
  623.    my($bkshlf, $bk) = @_;
  624.  
  625.    if ($bkshlf eq '' || $bk eq '' || !(-d "${bkshlf}/books/${bk}")) {
  626.        return 0;
  627.    }
  628.  
  629.    #--------------
  630.    # in PDF format
  631.    #
  632.    if (-d "${bkshlf}/books/${bk}/pdf"
  633.        &&
  634.        (-f "${bkshlf}/books/${bk}/pdf/${bk}.pdf" 
  635.         ||
  636.         -f "${bkshlf}/books/${bk}/${bk}.pdf")) {
  637.        return 1;
  638.    }
  639.  
  640.    return 0;
  641. }
  642.  
  643.  
  644.  
  645. #---------------------------------
  646. # clean_bookdir(string bk_dir, bk)
  647. #
  648. #  remove zero-length files/cruft
  649. #
  650. sub clean_bookdir {
  651.  
  652.    my($bk_dir, $bk) = @_;
  653.  
  654.    if ($bk_dir eq '' || !(-d "${bk_dir}")) {
  655.        return;
  656.    }
  657.  
  658.    my($s, $tmp)  = '';
  659.  
  660.    #----------------------
  661.    # remove 0-length files
  662.    #
  663.    foreach $s (split(/\n/, `(find ${bk_dir} -type f -size 0 -print)`)) {
  664.       unlink($s);     # ignore errors
  665.    }
  666.  
  667.    #-------------------------
  668.    # remove empty directories
  669.    # - use streamlined method
  670.    #
  671.    # @ents = split(/\n/, `(cd ${bk_dir}; find . -type d -print)`);
  672.    #
  673.    my(@ents) = ("${bk_dir}/ebt", "${bk_dir}/index", "${bk_dir}/styles");
  674.  
  675.    foreach $s (@ents) {
  676.       if (!(-e $s) || -l $s || !(-d $s)) {
  677.           next;       # ignore symlinks
  678.       }
  679.       rmdir($s);      # ignore errors
  680.    }
  681.  
  682.    if ($bk eq '') {
  683.        return;
  684.    }
  685.  
  686.    #------------------------------------------
  687.    # remove old infosearch files / ignore errs
  688.    #
  689.    if (-e "${bk_dir}/${bk}.inp") {
  690.       unlink("${bk_dir}/${bk}.inp");
  691.    }
  692.    if (-e "${bk_dir}/${bk}.html") {
  693.       unlink("${bk_dir}/${bk}.html");
  694.    }
  695.    if (-e "${bk_dir}/${bk}_help.html") {
  696.       unlink("${bk_dir}/${bk}_help.html");
  697.    }
  698.    if (-e "${bk_dir}/${bk}.books.wrd") {
  699.       unlink("${bk_dir}/${bk}.books.wrd");
  700.    }
  701.  
  702.    return;
  703. }
  704.  
  705.  
  706.  
  707. #--------------------
  708. # do_html(string ttl)
  709. #
  710. sub do_html {
  711.  
  712.    my($ttl) = @_;
  713.    my($s) = $_hdr;
  714.    $s =~ s/%TTL/$ttl/g;
  715.    return "$s";
  716. }
  717.  
  718.  
  719.  
  720. #----------------------
  721. # usage(string err_msg)
  722. #
  723. sub usage {
  724.  
  725.    my($err) = @_;
  726.  
  727.    print "\nusage: insightAdmin [-c] [-d] [-v] [-h] [ <bookshelf> ]\n",
  728.          "e.g. : insightAdmin ",
  729.          "/usr/share/Insight/library/SGI_bookshelves/SGI_EndUser\n\n",
  730.          "where: -c   correct my books (from old to new format)\n",
  731.          "       -d   use the network to connect to techpubs.sgi.com to try\n",
  732.          "            to download books during a -c(orrection) of books\n",
  733.          "       -v   verbose mode\n",
  734.          "       -h   print this usage message\n",
  735.          ($err ne '' ? "\n** insightAdmin ERROR:\n   ${err}\n\n" : '');
  736.  
  737.    exit(-1);
  738. }
  739.  
  740.  
  741.  
  742. __END__
  743.  
  744. <html>
  745.  <head>
  746.   <title>SGI Desktop Techpubs Library: %TTL</title>
  747.  </head>
  748.  
  749.  <body text="#000000" bgcolor="#f9f9f9">
  750.  
  751.  <table BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
  752.  <tr bgcolor="#003399"><td colspan="2"><font size="1"> </td></tr>
  753.  <tr bgcolor="#7C7F87">
  754.   <td valign="top" align="left"><p><br>
  755.   <font face="helvetica" color="#ffffff" size="+1"><b>
  756.      SGI Desktop Techpubs Library
  757.   </b></font><br> 
  758.   </p></td>
  759.   <td valign="center" align="right"><font face="helvetica" color="#ffffff"><b>
  760.   <a href="http://localhost/infosearch/"><font face="helvetica" color="#ffffff" style="text-decoration: none">infosearch</font></a>
  761.     |  
  762.   <a href="http://techpubs.sgi.com/"><font face="helvetica" color="#ffffff" style="text-decoration: none">techpubs.sgi.com</font></a>
  763.     
  764.   </b></font></td>
  765.  </tr>
  766.  <tr bgcolor="#003399"><td colspan="2"><font size="1"> </td></tr>
  767.  </table>
  768.  
  769.  <p>
  770.    <h3>SGI Desktop Techpubs Library: %TTL</h3>
  771.  </p>
  772.